############# ########### ####### ##### ### ##
#
# Copyright (C) 2010 The Hursk Group, LLC
#
# This program is free software: you can redistribute it and/or modify 
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (See file named COPYING).  If not, see 
# <http://www.gnu.org/licenses/>.
# 
############# ########### ####### ##### ### ##

BEGIN {
  RS=""
  FS="\n"
  #SUBSEP=":"
}

{
  if (debug == "2" ) print "$1: "$1
  for (x=1;x<=NF;x++) {
	split($x,tmp_arr,":  ")
	gsub(" ","",tmp_arr[1])
	if (tmp_arr[1] == "PKGINST") _pkginst = tmp_arr[2]
	if (tmp_arr[1] == "VERSION") _version = tmp_arr[2]
	#if (tmp_arr[1] == "PSTAMP") _pstamp = tmp_arr[2]
	#if (tmp_arr[1] == "NAME") _name = tmp_arr[2]
	#if (tmp_arr[1] == "FILES") next
	#if (debug == "2") print "tmp_arr[1]: "tmp_arr[1]"\ttmp_arr[2]: "tmp_arr[2]
  }
  #if (debug == "2" ) print "_pkginst: "_pkginst"\t_version: "_version"\t_pstamp: "_pstamp
  #pkg_arr[_pkginst,"pkginst"] = _pkginst
  #pkg_arr[_pkginst,"version"] = _version
  pkg_arr[_pkginst] = _pkginst":"_version
  #pkg_arr[_pkginst,"pstamp"] = _pstamp
  #pkg_arr[_pkginst,"name"] = _name
  delete tmp_arr
}

END {
  if ( ip != "" ) {
	ip = ip"\t"
  }

  for ( members in pkg_arr ) {
	#if (debug) { print "member: "members"\tpkg_arr[members]: "pkg_arr[members] } else print pkg_arr[members]
	#print "pkg_arr["members"]: "pkg_arr[members]
	print ip pkg_arr[members]
  }
}
